package com.zzj.ecology.system.service.impl.minitor;

import com.zzj.ecology.system.bean.minitor.SysLoginInfor;
import com.zzj.ecology.system.bean.minitor.SysLoginInforExample;
import com.zzj.ecology.system.domain.Page;
import com.zzj.ecology.system.dto.R;
import com.zzj.ecology.system.mapper.minitor.SysLoginInforMapper;
import com.zzj.ecology.system.service.minitor.SysLoginInforService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service("sysLoginInforService")
@Transactional(rollbackFor = Exception.class)
public class SysLoginInforServiceImpl implements SysLoginInforService {

    @Autowired
    private SysLoginInforMapper sysLoginInforMapper;

    /**
     * 插入一条日志
     * @param sysLoginInfor
     * @return
     */
    public int insert(SysLoginInfor sysLoginInfor) {
        return sysLoginInforMapper.insertSelective(sysLoginInfor);
    }

    /**
     * 分页查询 用户登录日志
     * @param page
     * @return
     */
    public R findPageList(Page page) {
        int currentPage = page.getCurrentPage();
        Integer pageCounts = page.getPageCounts();
        int first = (currentPage - 1) * pageCounts;

        List<SysLoginInfor> sublist = sysLoginInforMapper.findPageList(first, pageCounts);
        page.getData().put(R.LIST_TAG, sublist);// 当前页面数据

        SysLoginInforExample example = new SysLoginInforExample();
        List<SysLoginInfor> parlist = sysLoginInforMapper.selectByExample(example);//不分页总数据
        page.setTotalCounts(parlist.size());
        return R.ok().data(R.PAGE_TAG, page);
    }

    /**
     * 批量删除 用户登录日志，此操作非标识删除不可逆转（注意）。在操作日志中记录谁操作了此操作。
     * @param infoids
     * @return
     */
    public int deleteNonreversibleByIds(List<Integer> infoids) {
        return sysLoginInforMapper.deleteNonreversibleByIds(infoids);
    }
}
